package com.example.a66666.yuejian.Fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.a66666.yuejian.Adapter.ActivityAdapter;
import com.example.a66666.yuejian.Bean.ActivityBean;
import com.example.a66666.yuejian.Listener.RetrofitListener;
import com.example.a66666.yuejian.Loader.GlideImageLoader;
import com.example.a66666.yuejian.Model.UserModel;
import com.example.a66666.yuejian.R;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;

import java.util.ArrayList;
import java.util.List;
import java.util.zip.Inflater;

/**
 * A simple {@link Fragment} subclass.
 */
public class ActivityFragment extends Fragment {

    private Banner banner;
    private ArrayList<String> listPath;
    private RecyclerView recyclerView;
    private UserModel userModel;
    private RetrofitListener<List<ActivityBean>> listener;
    private LinearLayoutManager linearLayoutManager;
    private ActivityAdapter activityAdapter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,  Bundle savedInstanceState) {
           View view=inflater.inflate(R.layout.fragment_activity,container,false);
           activityAdapter=new ActivityAdapter();
           recyclerView=(RecyclerView)view.findViewById(R.id.activityRecyclerView);
           linearLayoutManager=new LinearLayoutManager(getActivity());
           linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
           recyclerView.setLayoutManager(linearLayoutManager);
           recyclerView.setAdapter(activityAdapter);
           initBanner(view);
           listener=new RetrofitListener<List<ActivityBean>>() {
               @Override
               public void onSuccess(List<ActivityBean> list) {
                   activityAdapter.setData(list);
               }

               @Override
               public void onFail(String msg) {

               }
           };
           userModel=new UserModel();
           userModel.getAllActivity(listener);
           return view;
    }

    public void initBanner(View view){
         banner=(Banner)view.findViewById(R.id.activityBanner);
         listPath=new ArrayList<>();
         listPath.add("http://10.0.2.2/yuejian/public/static/activityLBT/1.jpg");
         listPath.add("http://10.0.2.2/yuejian/public/static/activityLBT/2.jpg");
         listPath.add("http://10.0.2.2/yuejian/public/static/activityLBT/3.jpg");
         listPath.add("http://10.0.2.2/yuejian/public/static/activityLBT/4.jpg");
         banner.setBannerStyle(BannerConfig.NUM_INDICATOR);
         banner.setImageLoader(new GlideImageLoader());
         banner.setImages(listPath);
         banner.setBannerAnimation(Transformer.DepthPage);
         banner.setDelayTime(2000);
         banner.setIndicatorGravity(BannerConfig.CIRCLE_INDICATOR_TITLE_INSIDE);
         banner.start();
    }


}
